package com.chat.api.web.vo;

import com.chat.api.utils.util.DateUtil;
import com.chat.api.utils.util.ParamUtil;
import com.chat.api.web.po.BlogBean;
import lombok.Data;

import javax.persistence.Column;
import java.io.Serializable;

@Data
public class BlogEntity implements Serializable {
    private static final long serialVersionUID = 1L;

    private String id;
    private String userId;
    private String title;
    private String content;
    private String views = "0";
    private String remarkCount = "0";
    private String likeCount = "0";
    private String createDate;
    private String groupId;
    private String status;
    private String authorName;

    public void setValue(BlogBean bean){
        this.setId(String.valueOf(bean.getId()));
        this.setUserId(String.valueOf(bean.getUserId()));
        this.setTitle(bean.getTitle());
        this.setContent(bean.getContent());
        this.setViews(String.valueOf(bean.getViews()));
        this.setRemarkCount(String.valueOf(bean.getRemarkCount()));
        this.setLikeCount(String.valueOf(bean.getLikeCount()));
        this.setCreateDate(DateUtil.dateToStr(bean.getCreateDate(),6));
        this.setGroupId(String.valueOf(bean.getGroupId()));
        this.setStatus(bean.getStatus().toString());
        this.setAuthorName(bean.getAuthorName());
    }

    public void setBean(BlogBean bean){
        bean.setId(ParamUtil.getLongParameter(id,-1L));
        bean.setContent(content);
        bean.setLikeCount(Integer.valueOf(likeCount));
        bean.setRemarkCount(Integer.valueOf(remarkCount));
        bean.setTitle(title);
        bean.setUserId(ParamUtil.getLongParameter(userId,-1L));
        bean.setViews(Integer.valueOf(views));
        bean.setGroupId(ParamUtil.getLongParameter(groupId,-1L));
        bean.setStatus(status);
        bean.setAuthorName(authorName);
    }

    public BlogBean setBeanValue(){
        BlogBean bean = new BlogBean();
        bean.setUserId(ParamUtil.getLongParameter(this.getUserId(),-1L));
        bean.setTitle(this.getTitle());
        bean.setContent(this.getContent());
        bean.setViews(Integer.parseInt(this.getViews()));
        bean.setRemarkCount(Integer.parseInt(this.getRemarkCount()));
        bean.setLikeCount(Integer.parseInt(this.getLikeCount()));
        bean.setCreateDate(DateUtil.strToDate(this.getCreateDate(),6));
        return bean;
    }

}
